<!DOCTYPE html>
<html lang="zh">
<head>
    <th:block th:include="include :: header('用户列表')" />
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-5">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal" id="toAdd">
                        <h3 class="m-t-none m-b">注册</h3>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用户名：</label>

                            <div class="col-sm-8">
                                <input type="text" name="loginName" placeholder="用户名" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">密码：</label>

                            <div class="col-sm-8">
                                <input type="password" name="passowrd" placeholder="密码" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-8">
                                <button class="btn btn-sm btn-white" type="submit" onclick="addSave()">注 册</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "web/WebUser";
    $(function () {
        jQuery.validator.addMethod("isPassword", function(value, element) {
            var reg = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>,.\/]).{6,20}/;
            return reg.test(value);
        }, "密码中必须包含含数字、字母、特殊符号");
    })

    $("#toAdd").validate({
        onkeyup: false,
        rules:{
            loginName:{
                minlength: 1,
                maxlength: 20,
                remote: {
                    url: prefix + "/checkNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "loginName": function() {
                            return $.common.trim($("input[name='loginName']").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            passowrd:{
                minlength: 6,
                isPassword: true
            },
        },
        messages: {
            "loginName": {
                remote: "名称存在"
            }
        },
        focusCleanup: true
    });

    function addSave() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/addSave", $('#toAdd').serialize());
        }
    }
</script>
</body>
</html>
